/**
 * TODO
 *
 */
package org.zjt.rabbit.demo.queues;

import org.zjt.rabbit.demo.common.ContantsConfig;
import com.rabbitmq.client.*;
/**
 * 生产者
 * 一个队列多个消费者分工消费。fanout是一个消息发送给不同的队列。
 */
public class Productor {

	private static final String TASK_QUEUE_NAME = "task_queue";

	public static void main(String[] argv) throws java.io.IOException, Exception {

		ConnectionFactory factory = new ConnectionFactory();

		factory.setHost(ContantsConfig.MQ_HOST);
		Connection connection = factory.newConnection();
		Channel channel = connection.createChannel();
		channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
//		分发消息
		for(int i = 0 ; i < 5; i++){
			String message = "Hello World! " + i;
			channel.basicPublish("", "", MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
			System.out.println(" [x] Sent '" + message + "'");
		}



		Thread.sleep(6000);

		channel.close();
		connection.close();
	}
}
